<template>
	<view>
		<view class="title">
			<view class="line"></view>
			<view class="titleName" style="width: 96%;">
				<view style="float: left;">满减券</view>
				<view @click="add" style="float: right;font-size: 28rpx; font-weight: bold; color: #84BD00;">添加</view>
				<view style="clear: both;"></view>
			</view>
		</view>
		<view class="lc-new-box" v-for="(item,index) in coupon_list">
			<image :src="baseurl+'/imgs/505bd342074738cd5a3cf2da2bf0a13.png'" mode="widthFix"></image>
			<view class="lc-detail">
				<view class="lc-down">
					<view class="lc-price">满{{item.limit}}减{{item.price}}</view>
					<view class="lc-num" v-if="item.drawlimit>0">每人限制{{item.drawlimit}}张</view>
				</view>
				<view class="lc-fies">
					<view class="lc-coms">
						<view class="lc-words">{{item.content||''}}</view>
						<view class="lc-money"><text>￥</text>{{item.price}}</view>
					</view>
					<view style="display: flex;">
						<view class="lc-buy" @click="edit(item.id)">
							编辑
						</view>
						<view class="lc-buy" style="background-color: cadetblue;" @click="del(item.id)">
							删除
						</view>
					</view>
					
					
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				app: getApp().globalData,
				baseurl: getApp().globalData.baseurl,
				shop_id:'',
				coupon_list:[]
			}
		},
		methods:{
			index(){
				var that = this
				this.app.post('/api/project/coupon_list', {
					shop_id: this.shop_id
				}).then(res => {
					that.coupon_list = res.list
					uni.hideLoading()
				})
			},
			edit(id){
				this.$wanlshop.to(`/pages/lc/kzt/coupon_add?id=`+id+'&shop_id='+this.shop_id);
			},
			add(){
				this.$wanlshop.to(`/pages/lc/kzt/coupon_add?shop_id=`+this.shop_id);
			},
			del(id){
				var that = this
				
				uni.showModal({
				  title: '删除确认', // 标题文字，支持字符串或空值
				  content: '确定执行此操作吗？', // 正文内容，支持换行符\r\n
				  showCancel: true, // 是否显示取消按钮（默认true）
				  cancelText: '取消', // 取消按钮文字（默认"取消"）
				  cancelColor: '#999', // 取消按钮文字颜色（默认#000）
				  confirmText: '确定', // 确认按钮文字（默认"确定"）
				  confirmColor: '#007AFF', // 确认按钮颜色（默认#3CC51F）
				  success: res => {
				    if (res.confirm) {
				      console.log('用户确认操作');
					  that.app.post('/api/project/coupon_del', {
					  	id: id
					  }).then(res => {
						  uni.showToast({
						  	title:'删除成功'
						  })
						  setTimeout(function(){
							  that.index() 
						  },2000)
					  })
				      // 执行确认逻辑
				    } else if (res.cancel) {
				      console.log('用户取消操作');
				      // 执行取消逻辑
				    }
				  }
				});

			}
		},
		onLoad(e) {
			console.log(e)
			if(e.shop_id){
				this.shop_id = e.shop_id
				this.index()
			}
		},
		onShow() {
			this.index()
		}
	}
</script>

<style lang="scss">
	.title {
		width: 664rpx;
		margin-left: 43rpx;
		display: flex;
		align-items: center;
		margin-top: 30rpx;
		margin-bottom: 30rpx;
		position: relative;
	
		.line {
			width: 8rpx;
			height: 34rpx;
			background-color: #84BD00;
			border-radius: 50rpx;
		}
	
		.titleName {
			font-size: 33rpx;
			color: #3D3D3D;
			margin-left: 17rpx;
		}
	
		.comment-all {
			display: flex;
			align-items: center;
			position: absolute;
			right: 0;
	
			view {
				font-size: 24rpx;
				color: #999999;
			}
	
			image {
				width: 24rpx;
				height: 24rpx;
				margin-left: 4rpx;
			}
		}
	}
	.lc-new-box {
		width: 690rpx;
		height: 160rpx;
		position: relative;
		margin-left: 30rpx;
	
		image {
			width: 690rpx;
			height: 160rpx;
		}
	
		.lc-detail {
			position: absolute;
			top: 0;
			left: 0;
			width: 690rpx;
			height: 160rpx;
			display: flex;
			flex-wrap: wrap;
			align-content: center;
	
			.lc-down {
				width: 630rpx;
				margin-left: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
	
				.lc-price {
					font-size: 30rpx;
					color: #3D3D3D;
				}
	
				.lc-num {
					font-size: 24rpx;
					color: #999999;
				}
			}
	
			.lc-fies {
				width: 630rpx;
				margin-left: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 10rpx;
	
				.lc-coms {
					.lc-words {
						font-size: 24rpx;
						color: #999999;
					}
	
					.lc-money {
						font-size: 36rpx;
						color: #FB4E2F;
	
						text {
							font-size: 26rpx;
						}
					}
				}
	
				.lc-buy {
					width: 136rpx;
					height: 64rpx;
					background-color: #FB4E2F;
					color: #FFFFFF;
					font-size: 26rpx;
					border-radius: 50rpx;
					display: flex;
					justify-content: center;
					align-items: center;
				}
			}
		}
	}
	
</style>